<!DOCTYPE html>
<html>
<head>
  <title>密码隐藏和显示</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      text-align: center;
    }
    
    .hidden-password {
      display: none;
    }
    
    #countdown {
      font-size: 3em;
      color: red;
      margin-top: 2em;
    }
    
    #password {
      margin-top: 2em;
      font-size: 1.5em;
    }
    
    #show-password {
      margin-top: 1em;
      font-size: 1.2em;
      padding: 0.5em 1em;
      background-color: #4CAF50;
      color: white;
      border: none;
      border-radius: 0.5em;
      cursor: pointer;
    }
  </style>
</head>
<body>
  <h1>密码隐藏和显示</h1>

  <!-- 密码输入框 -->
  <input type="password" id="password">

  <!-- 显示密码按钮 -->
  <button onclick="showPassword()" id="show-password" class="hidden-password">显示密码</button>

  <!-- 跳转倒计时 -->
  <div id="countdown"></div>

  <script>
    // 倒计时跳转
    var countdownElement = document.getElementById("countdown");
    var countdownTime = 5;

    function countdown() {
      countdownElement.classList.remove("hidden-password");
      countdownElement.textContent = countdownTime;

      if (countdownTime > 0) {
        countdownTime--;
        setTimeout(countdown, 1000);
      } else {
        redirectToPage();
      }
    }

    function redirectToPage() {
      var newTab = window.open("https://www.baidu.com", "_blank");
      newTab.focus();
    }

    countdown();

    // 返回后显示密码
    window.addEventListener("pageshow", function(event) {
      var passwordInput = document.getElementById("password");
      passwordInput.value = "123456";
      passwordInput.classList.remove("hidden-password");
      document.getElementById("show-password").classList.remove("hidden-password");
    });

    // 显示密码
    function showPassword() {
      var passwordInput = document.getElementById("password");
      passwordInput.type = "text";
    }
  </script>
</body>
</html>
